<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 预约充电</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
            min-height: 100vh;
            display: flex;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
        }

        .sidebar-header .logo {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .sidebar-header .logo-icon {
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 18px;
            color: var(--light-color);
        }

        .sidebar-header h3 {
            font-size: 1.2rem;
            font-weight: 500;
            margin: 0;
        }

        .sidebar-header p {
            font-size: 0.8rem;
            opacity: 0.8;
            margin: 0;
        }

        .nav-menu {
            list-style: none;
            padding: 0 15px;
        }

        .nav-item {
            margin-bottom: 5px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            border-radius: 8px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .nav-link i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 16px;
        }

        .nav-link .badge {
            margin-left: auto;
            background-color: var(--light-color);
            color: var(--dark-color);
            font-size: 0.7rem;
            padding: 3px 6px;
        }

        .user-profile {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            padding: 0 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
        }

        .user-info:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 14px;
        }

        .user-name {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.7rem;
            opacity: 0.8;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .btn i {
            margin-right: 6px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
        }

        .btn-outline:hover {
            background-color: #f5f5f5;
        }

        /* 预约表单容器 */
        .reservation-container {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 30px;
            max-width: 800px;
            margin: 0 auto;
        }

        /* 充电桩信息卡片 */
        .pile-info-card {
            display: flex;
            margin-bottom: 30px;
            border-bottom: 1px solid #eee;
            padding-bottom: 20px;
        }

        .pile-image {
            width: 150px;
            height: 100px;
            border-radius: 8px;
            object-fit: cover;
            margin-right: 20px;
        }

        .pile-details {
            flex: 1;
        }

        .pile-name {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .pile-code {
            font-size: 0.9rem;
            color: #777;
            margin-bottom: 10px;
        }

        .pile-specs {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
        }

        .spec-item {
            display: flex;
            align-items: center;
            font-size: 0.85rem;
            color: #555;
        }

        .spec-item i {
            margin-right: 5px;
            color: var(--primary-color);
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }

        .form-row {
            display: flex;
            gap: 15px;
            margin-bottom: 15px;
        }

        .form-col {
            flex: 1;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 0.9rem;
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(0, 168, 150, 0.1);
        }

        .form-select {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 10px center;
            background-size: 1em;
        }

        /* 费用估算 */
        .cost-estimate {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .estimate-title {
            font-size: 1rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 15px;
        }

        .estimate-details {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        }

        .estimate-label {
            color: #777;
        }

        .estimate-value {
            font-weight: 500;
        }

        .estimate-total {
            border-top: 1px solid #eee;
            padding-top: 10px;
            margin-top: 10px;
            font-size: 1.1rem;
            font-weight: 600;
            color: var(--primary-color);
            display: flex;
            justify-content: space-between;
        }

        /* 支付方式 */
        .payment-methods {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
        }

        .payment-method {
            flex: 1;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 15px;
            cursor: pointer;
            transition: var(--transition);
            text-align: center;
        }

        .payment-method:hover {
            border-color: var(--primary-color);
        }

        .payment-method.selected {
            border-color: var(--primary-color);
            background-color: rgba(0, 168, 150, 0.05);
        }

        .payment-icon {
            font-size: 2rem;
            margin-bottom: 10px;
            color: var(--primary-color);
        }

        .payment-name {
            font-weight: 500;
        }

        /* 表单操作按钮 */
        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 15px;
            margin-top: 30px;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
                overflow: hidden;
            }

            .main-content {
                margin-left: 70px;
            }
        }

        @media (max-width: 768px) {
            .pile-info-card {
                flex-direction: column;
            }

            .pile-image {
                width: 100%;
                height: 150px;
                margin-right: 0;
                margin-bottom: 15px;
            }

            .form-row {
                flex-direction: column;
                gap: 0;
            }

            .payment-methods {
                flex-direction: column;
            }
        }

        @media (max-width: 576px) {
            .main-content {
                padding: 20px 15px;
            }

            .reservation-container {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div>
                <h3>绿能充</h3>
                <p>用户面板</p>
            </div>
        </div>
    </div>

    <ul class="nav-menu">
        <li class="nav-item">
            <a href="/user/home" class="nav-link active">
                <i class="fas fa-tachometer-alt"></i>
                <span>仪表盘</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/announcement/list" class="nav-link">
                <i class="fas fa-users"></i>
                <span>公告栏</span>
                <span class="badge">5</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/pile/list" class="nav-link">
                <i class="fas fa-charging-station"></i>
                <span>充电桩</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/map/mapDetail" class="nav-link">
                <i class="fas fa-list-alt"></i>
                <span>地图</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/user/center/personCenter/${user.id}" class="nav-link">
                <i class="fas fa-exclamation-triangle"></i>
                <span>个人中心</span>
                <span class="badge">3</span>
            </a>
        </li>
    </ul>

    <div class="user-profile">
        <div class="user-info">
            <div class="user-avatar">
                <i class="fas fa-user"></i>
            </div>
            <div>
                <div class="user-name">${user.username}</div>
                <div class="user-role">
                    <c:choose>
                        <c:when test="${user.role == 1}">管理员</c:when>
                        <c:otherwise>普通用户</c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <div class="header">
        <div class="page-title">
            <h1>预约充电</h1>
            <p>填写预约信息并确认</p>
        </div>
        <div class="header-actions">
            <button class="btn btn-outline" onclick="window.history.back()">
                <i class="fas fa-arrow-left"></i> 返回
            </button>
        </div>
    </div>

    <div class="reservation-container">
        <!-- 充电桩信息 -->
        <div class="pile-info-card">
            <img src="https://picsum.photos/300/200?random=${chargingPile.id}" alt="充电桩图片" class="pile-image">
            <div class="pile-details">
                <div class="pile-name">${chargingPile.name}</div>
                <div class="pile-code">编号: ${chargingPile.code}</div>
                <div class="pile-specs">
                    <div class="spec-item">
                        <i class="fas fa-bolt"></i> ${chargingPile.type == 'AC' ? '交流' : '直流'} ${chargingPile.power}kW
                    </div>
                    <div class="spec-item">
                        <i class="fas fa-money-bill-wave"></i> ¥${chargingPile.price}/度
                    </div>
                    <div class="spec-item">
                        <i class="fas fa-map-marker-alt"></i> ${chargingPile.location}
                    </div>
                </div>
            </div>
        </div>

        <form id="reservationForm" action="${pageContext.request.contextPath}/user/record/add" method="post">
            <input type="hidden" name="pileId" value="${chargingPile.id}">

            <!-- 预约时间 -->
            <div class="form-group">
                <h3 style="color: var(--dark-color); margin-bottom: 15px;">预约时间</h3>
                <div class="form-row">
                    <div class="form-col">
                        <label for="reservationDate" class="form-label">预约日期</label>
                        <input type="date" id="reservationDate" name="reservationDate" class="form-control" required>
                    </div>
                    <div class="form-col">
                        <label for="startTime" class="form-label">开始时间</label>
                        <input type="time" id="startTime" name="startTime" class="form-control" required>
                    </div>
                    <div class="form-col">
                        <label for="duration" class="form-label">充电时长</label>
                        <select id="duration" name="duration" class="form-control form-select" required>
                            <option value="1">1小时</option>
                            <option value="2">2小时</option>
                            <option value="3">3小时</option>
                            <option value="4">4小时</option>
                            <option value="5">5小时</option>
                            <option value="6">6小时</option>
                            <option value="8">8小时</option>
                        </select>
                    </div>
                </div>
            </div>

            <!-- 费用估算 -->
            <div class="cost-estimate">
                <div class="estimate-title">费用估算</div>
                <div class="estimate-details">
                    <span class="estimate-label">充电价格</span>
                    <span class="estimate-value">¥${chargingPile.price}/度</span>
                </div>
                <div class="estimate-details">
                    <span class="estimate-label">预计充电量</span>
                    <span class="estimate-value" id="estimatedEnergy">0 度</span>
                </div>
                <div class="estimate-details">
                    <span class="estimate-label">服务费</span>
                    <span class="estimate-value">¥0.00</span>
                </div>
                <div class="estimate-total">
                    <span>预计总费用</span>
                    <span id="estimatedCost">¥0.00</span>
                </div>
            </div>

            <!-- 支付方式 -->
            <div class="form-group">
                <h3 style="color: var(--dark-color); margin-bottom: 15px;">支付方式</h3>
                <div class="payment-methods">
                    <label class="payment-method selected">
                        <input type="radio" name="paymentMethod" value="BALANCE" checked style="display: none;">
                        <div class="payment-icon">
                            <i class="fas fa-wallet"></i>
                        </div>
                        <div class="payment-name">账户余额</div>
                        <div style="font-size: 0.8rem; color: #777;">当前余额: ¥${user.balance}</div>
                    </label>
                    <label class="payment-method">
                        <input type="radio" name="paymentMethod" value="ALIPAY" style="display: none;">
                        <div class="payment-icon">
                            <i class="fab fa-alipay"></i>
                        </div>
                        <div class="payment-name">支付宝</div>
                    </label>
                    <label class="payment-method">
                        <input type="radio" name="paymentMethod" value="WECHAT" style="display: none;">
                        <div class="payment-icon">
                            <i class="fab fa-weixin"></i>
                        </div>
                        <div class="payment-name">微信支付</div>
                    </label>
                </div>
            </div>

            <!-- 备注信息 -->
            <div class="form-group">
                <label for="note" class="form-label">备注信息 (可选)</label>
                <textarea id="note" name="note" class="form-control" rows="3" placeholder="如有特殊需求请在此填写"></textarea>
            </div>

            <!-- 表单操作 -->
            <div class="form-actions">
                <button type="button" class="btn btn-outline" onclick="window.history.back()">
                    <i class="fas fa-times"></i> 取消
                </button>
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-check"></i> 确认预约
                </button>
            </div>
        </form>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 设置默认日期为今天
        const today = new Date().toISOString().split('T')[0];
        document.getElementById('reservationDate').value = today;

        // 设置默认开始时间为当前时间的下一个整点
        const now = new Date();
        const nextHour = new Date(now.getTime() + (60 - now.getMinutes()) * 60000);
        const hours = String(nextHour.getHours()).padStart(2, '0');
        const minutes = String(nextHour.getMinutes()).padStart(2, '0');
        document.getElementById('startTime').value = `${hours}:${minutes}`;

        // 计算并显示预计费用
        calculateEstimatedCost();

        // 监听时长变化，重新计算费用
        document.getElementById('duration').addEventListener('change', calculateEstimatedCost);

        // 支付方式选择
        const paymentMethods = document.querySelectorAll('.payment-method');
        paymentMethods.forEach(method => {
            method.addEventListener('click', function() {
                paymentMethods.forEach(m => m.classList.remove('selected'));
                this.classList.add('selected');
                this.querySelector('input[type="radio"]').checked = true;
            });
        });

        // 表单提交
        document.getElementById('reservationForm').addEventListener('submit', function(e) {
            e.preventDefault();

            // 验证表单
            const startTime = document.getElementById('startTime').value;
            const duration = document.getElementById('duration').value;

            if (!startTime) {
                alert('请选择开始时间');
                return;
            }

            if (!duration || duration <= 0) {
                alert('请选择充电时长');
                return;
            }

            // 提交表单
            this.submit();
        });
    });

    // 计算预计费用
    function calculateEstimatedCost() {
        const price = ${chargingPile.price};
        const duration = parseInt(document.getElementById('duration').value);

        // 假设平均充电功率为7kW（交流）或60kW（直流）
        const power = '${chargingPile.type}' === 'AC' ? 7 : 60;
        const estimatedEnergy = power * duration;
        const estimatedCost = estimatedEnergy * price;

        document.getElementById('estimatedEnergy').textContent = estimatedEnergy.toFixed(1) + ' 度';
        document.getElementById('estimatedCost').textContent = '¥' + estimatedCost.toFixed(2);
    }
</script>
</body>
</html>